﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>工程案例管理中心</title>
    <link href="~/Content/jquery-easyui-1.3.1/themes/icon.css" rel="stylesheet" />
    <link href="~/Content/jquery-easyui-1.3.1/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/Content/Site.css" rel="stylesheet" />

    <script src="~/Content/jquery-easyui-1.3.1/jquery-1.8.0.min.js"></script>
    <script src="~/Content/jquery-easyui-1.3.1/jquery.easyui.min.js"></script>
    <script src="~/Content/jquery-easyui-1.3.1/locale/easyui-lang-zh_CN.js"></script>

    @*修改时间格式的Js文件*@
    <script src="~/Content/jquery-easyui-1.3.1/datapattern2.js"></script>

    <script src="~/Scripts/ckeditor/ckeditor.js"></script>
    
    <script type="text/javascript">
        $.fn.datebox.defaults.formatter = function (date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
        };
        $.fn.datebox.defaults.parser = function (s) {
            if (!s) return new Date();
            var ss = s.split('-');
            var y = parseInt(ss[0], 10);
            var m = parseInt(ss[1], 10);
            var d = parseInt(ss[2], 10);
            if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
                return new Date(y, m - 1, d);
            } else {
                return new Date();
            }
        };
    </script>
     <script type="text/javascript">
         $(function () {

             //初始化弹出窗体
             initTable();
             //实现添加用户角色信息
             AddStudent();

         });

         //初始化表格 
         function initTable(queryData) {
             $('#test').datagrid({
                 title: '专业文献管理',
                 iconCls: 'icon-save',
                 height: 400,
                 nowrap: true,
                 autoRowHeight: false,
                 striped: true,
                 collapsible: true,
                 url: '/Literature/GetAllLiterature',
                 sortName: 'ID',
                 sortOrder: 'asc',
                 //striped:true,
                 border: true,
                 remoteSort: false,
                 idField: 'ID',
                 pagination: true,
                 rownumbers: true,
                 queryParams: queryData,
                 columns: [[
                     { field: 'ck', checkbox: true },
                     { field: 'ID', title: 'ID', width: 50, sortable: true },
                     { field: 'Title', title: '文当标题', width: 100, sortable: true },
                     { field: 'Author', title: "作者", width: 150, sortable: true, },
                     { field: 'Count', title: "浏览次数", width: 150, sortable: true, },
                     {
                         field: 'CreateDateTime', title: "创建时间", width: 150, sortable: true,
                         formatter: function (value, row, index) {
                             return (eval(value.replace(/\/Date\((\d+)\)\//gi, "new Date($1)")));
                             //.pattern("yyyy-M-d h:m:s")
                         }
                     }
                 ]],

                 toolbar: [{
                     id: 'btnadd',
                     text: '添加文档',
                     iconCls: 'icon-add',
                     handler: function () {
                         //实现弹出添加文档的层
                         ShowCreateArticle();
                     }
                 }, '-', {
                     id: 'btncut',
                     text: '修改文档',
                     iconCls: 'icon-cut',
                     handler: function () {
                         //实现弹出修改文档的层
                         ShowUpdateArticleDialog();
                     }
                 }, '-', {
                     id: 'btnsave',
                     text: '删除文档',
                     iconCls: 'icon-remove',
                     handler: function () {

                         DeleteArticleByClick();
                     }
                 }]
             });
         }
         //弹出文档添加页面
         function ShowCreateArticle() {
             $("#AddStudentDialog").dialog('open').dialog('setTitle', "添加文档信息");
             //再次打开的时候清空文本框中的值
         }
         //实现添加的操作
         function AddStudent() {
             $("#btnAdd").click(function () {
                 //验证表单是否通过
                 var validate = $('#StudentAdd').form('validate');
                 if (validate == false) {
                     return false;
                 }

                 //构造传递的参数，
                 var da = CKEDITOR.instances.Content1.getData();
                 var postData = {
                     Title: $("#Title").val(),
                     //Category: $("#Category").combobox('getValue'),
                     CreateDateTime: $("#CreateDateTime").val(),
                     Category: $("#Category").val(),
                     //Category: $("#Category").val(),
                     Content1:escape(da),
                    // Content1: $("#content").val(),
                     Count: $("#Title").val(),
                     Author: $("#Author").val(),
                 }

                 //异步传递数据到前台进行添加
                 $.post("/Project/AddFile", postData, function (data) {
                     if (data = "OK") {
                         $.messager.alert("友情提示", "添加成功");
                         //关闭层，刷新表单
                         $("#AddStudentDialog").dialog('close');
                         $("#test").datagrid('reload');
                     }
                     else {
                         $.messager.alert("友情提示", "添加失败，请您检查");
                     }
                 });

             })
         }

   

        ////选择文件事件
        //function fileSelected() {
        //    var file = document.getElementById('fileToUpload').files[0];
        //    var fileName = file.name;
        //    var file_typename = fileName.substring(fileName.lastIndexOf('.'), fileName.length);

        //    if (file_typename == '.xls' || file_typename == '.doc' || file_typename == '.ppt') {//这里限定上传文件文件类型
        //        if (file) {

        //            var fd = new FormData();
        //            fd.append("fileToUpload", document.getElementById('fileToUpload').files[0]);
        //            var xhr = new XMLHttpRequest();
        //            xhr.upload.addEventListener("progress", uploadProgress, false);
        //            xhr.addEventListener("load", uploadComplete, false);
        //            xhr.addEventListener("error", uploadFailed, false);
        //            xhr.addEventListener("abort", uploadCanceled, false);
        //            xhr.open("POST", "/Protect/ToLead");
        //            xhr.send(fd);
        //            xhr.onreadystatechange = function () {
        //                //当服务器将数据返回给客户端时,readyState状态值为4   
        //                if (xhr.readyState == 4) {
        //                    if (xhr.status == 200) {
        //                        $.messager.alert("友情提示", "文件上传成功！");
        //                        $("#test").datagrid('reload');
        //                    }
        //                }
        //            }
        //            var fileSize = 0;
        //            if (file.size > 1024 * 1024)
        //                fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
        //            else
        //                fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
        //            document.getElementById('fileName').innerHTML = '文件名: ' + file.name;
        //            document.getElementById('fileSize').innerHTML = '大小: ' + fileSize;
        //            document.getElementById('fileType').innerHTML = '类型: ' + file.type;
        //        }
        //    }
        //    else {
        //        $("#uploadFile").hide();
        //        document.getElementById('fileName').innerHTML = "<span style='color:Red'>错误提示:上传文件应该是office文件而不应该是" + file_typename + ",请重新选择文件</span>"
        //        document.getElementById('fileSize').innerHTML = "";
        //        document.getElementById('fileType').innerHTML = "";
        //    }
        //}

        //function uploadProgress(evt) {
        //    if (evt.lengthComputable) {
        //        var percentComplete = Math.round(evt.loaded * 100 / evt.total);
        //        //$('#progressNumber').progressbar('setValue', percentComplete);
        //        $('#progressNumber').progressbar('setValue', 2);
        //        var seconds = 1;
        //        $('#progressNumber').progressbar('option', 'setValue', seconds);
        //        seconds++;
        //    }
        //    else {
        //        document.getElementById('progressNumber').innerHTML = '无法计算';
        //    }
        //}

        ////实现添加的操作
        //function AddArticle() {
        //    $("#btnAdd").click(function () {
        //        //验证表单是否通过
        //        var validate = $('#ff').form('validate');
        //        if (validate == false) {
        //            return false;
        //        }
        //        else {
        //            //构造传递的参数，
        //            var postData = {
        //                Title: $("#Title").val(),
        //                //Category: $("#Category").combobox('getValue'),
        //                CreateDateTime: $("#CreateDateTime").val(),
        //                Category: $("#Category").val(),
        //                //Category: $("#Category").val(),
        //                Content: CKEDITOR.instances['Content1'].getData(),
        //                Count: $("#Title").val(),
        //                Author: $("#Author").val(),
        //            };
        //        }
        //        //异步传递数据到前台进行添加
        //        $.post("/Project/AddFile", postData, function (data) {
        //            if (data == "OK") {
        //                $.messager.alert("友情提示", "添加成功");
        //            }
        //            else {
        //                $.messager.alert("友情提示", "添加失败，请您检查");
        //            }
        //        });

        //    });
        //}
    </script>
</head>

<body>
     <div>
        <table id="test"></table>
    </div>
     @*----------------------------设置添加的弹出层--------------------------------*@
    <div id="AddStudentDialog" class="easyui-dialog" style="width:660px;height:600px;padding:10px 20px"
			closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="StudentAdd" method="post" novalidate="novalidate">
            <table id="tblAdd">
                <tr>
                    <th colspan="2" >添加文档</th>
                </tr>
                <tr>
                    <td><label for="Title">标题：</label></td>
                    <td><input class="easyui-validatebox" type="text" id="Title" name="Title" data-options="required:true,validType:'length[1,32]'" /></td>
                </tr>
                <tr>
                    <td><label for="Category">所属类别：</label></td>
                <td><select id="Category" name="Category" editable="false" class="easyui-combobox" style="width: 200px">
                    <option value="1">业务范围</option>
                    <option value="2">工程实例</option>
                    <option value="3">技术优势</option>
                </select></td>
                </tr>
                    
                     <tr>
                    <td><label for="Content1">内容:</label></td>
                         <td>                         
                             <textarea cols="80" rows="10" id="Content1" name="Content1"></textarea>
                <script type="text/javascript">
                    CKEDITOR.replace('Content1', {
                        skin: 'kama',
                        height: 200,
                        width: 500
                    });
                </script>
                         </td>
                </tr>
                <tr>
                    <td><label for="CreateDateTime">创建日期：</label>
                </td>   
                    <td>
                         <input class="easyui-validatebox" type="date" id="CreateDateTime" name="CreateDateTime" data-

options="required:true,validType:'length[1,32]'" />
                         </td>
                </tr>
                
                 <tr>
                    <td><label for="Author">作者：</label>
                </td>
                    <td><input class="easyui-validatebox" type="text" id="Author" name="Author" data-options="required:true,validType:'length[1,32]'" /></td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align:center; padding-top:10px">
                        <a href="javascript:void(0)" class="easyui-linkbutton" id="btnAdd" iconcls="icon-ok" >确定</a>
                        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#AddStudentDialog').dialog('close')">关闭</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</body>
</html>
